#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
    const int inf = 0x7f7f7f7f;
    int methodsSumToTarget(vector<int> &nums, int target) {
        int n = nums.size();
        vector<int> dp(target + 1, 0);
        dp[0] = 1;
        for (auto &num : nums) {
            for (int t = target; t >= num; --t) {
                dp[t] += dp[t - num];
            }
        }
        return dp[target];
    }
};

int main() {
    vector<int> nums;
    int target;
    cin >> target;
    int n;
    while (cin >> n) {
        for (int i = 1; n * i <= target; i *= 2) {
            nums.push_back(n*i);
        }
    }
    cout << Solution().methodsSumToTarget(nums, target);
    return 0;
}